<template>
	<jk-dialog
		v-model="showDialog"
		title="新增-前纺计划"
		width="1400px"
		:confirm-btn-loading="saveBtnLoading"
		append-to-body
		fullscreen
		@on-cancel="onVisibleChange(false)"
		@on-visible-change="onVisibleChange"
		@on-confirm="onConfirmBtnOfDialog"
	>
		<form-box
			ref="frontPlanFormBox"
			create-method="dialog"
			page-type="add"
			:height="dialogTableHeight + 50"
			:order-id="orderId"
			@on-res="onRes"
		></form-box>
	</jk-dialog>
</template>

<script>
    import calHeight from '/src/mixins/cal-dialog-height';
    import formBox from '../../foreSpinPrd/foreSpinningPlan/components/form-box';
    export default {
        props: {
            dialogState: {
                type: Boolean,
                default: false
            },
            orderId: {
                type: [String, Number],
                default: ''
            }
        },
        components: {
            formBox
        },
        mixins: [calHeight],
        data() {
            return {
                showDialog: false,
                saveBtnLoading: false
            };
        },
        methods: {
            onRes(isSuccess) {
                this.saveBtnLoading = false;
                if (isSuccess) {
                    this.$emit('on-finish', isSuccess);
                }
            },
            onConfirmBtnOfDialog() {
                this.saveBtnLoading = true;
                this.$refs.frontPlanFormBox.onConfirmBtn(0);
            },
            onVisibleChange(e) {
                this.$emit('on-visible-change', e);
                if (!e) {
                    this.$refs.frontPlanFormBox.clearCacheMethod();
                }
            }
        },
        watch: {
            dialogState(newVal) {
                this.showDialog = newVal;
                if (newVal) {
                    this.$nextTick(() => {
                        this.$refs.frontPlanFormBox.getDependentData();
                    });
                }
            }
        }
    };
</script>
